﻿using System.Linq;
using Company.Merchandising.BusinessLayer.DataEntities;
using CompanyEntity = Company.Merchandising.BusinessLayer.DataEntities.Company;

namespace Company.Merchandising.DataAccessLayer.DataAccessCommon
{
	public class DACCompany : DACBase
	{
		public DACCompany(MerchModelEntities modelEntities) : base(modelEntities) { }

		public IQueryable<CompanyEntity> GetAllCompanies()
		{
			return from comp in _modelEntities.Company where !comp.IsDeleted select comp;
		}

		public IQueryable<CompanyEntity> GetCompaniesByNameOtherThan(string companyName, int companyId)
		{
			return from comp in _modelEntities.Company where comp.Name == companyName && comp.Id != companyId select comp;
		}

		public IQueryable<CompanyEntity> GetCompaniesByName(string companyName)
		{
			return from comp in _modelEntities.Company where comp.Name == companyName select comp;
		}

		public CompanyEntity GetCompanyById(int companyId)
		{
			return (from comp in _modelEntities.Company where comp.Id == companyId select comp).FirstOrDefault();
		}

		public IQueryable<CompanyEntity> GetDefaultCompaniesOtherThan(string companyName)
		{
			return from comp in _modelEntities.Company where comp.IsDefault && comp.Name != companyName select comp;
		}
	}
}
